package cn.neusoft.yuejian307.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.neusoft.yuejian307.R;
import cn.neusoft.yuejian307.activity.ActivityDetail;
import cn.neusoft.yuejian307.bean.Choiceness;

import static cn.neusoft.yuejian307.GloableVirable.IMG_URL;


public class ActivityAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
private Context mContext;
private List<Choiceness.ActivitydataBean> mList;
public LayoutInflater mLayoutInflater;

public ActivityAdapter(Context mContext, List<Choiceness.ActivitydataBean> List) {
        this.mContext = mContext;
        this.mList = List;
        mLayoutInflater = LayoutInflater.from(mContext);
        }

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_activity, parent, false);
        ViewHolder v = new ViewHolder(view);

        return v;
        }

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final Choiceness.ActivitydataBean club = (Choiceness.ActivitydataBean) mList.get(position);
        if (null == club)
        return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.name.setText(club.getActivity_name());
        if(club.getActivity_picture()!=null) {
        Picasso.with(mContext).load(IMG_URL+club.getActivity_picture()).into(viewHolder.pic);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
        Intent intent = new Intent(mContext, ActivityDetail.class);
        Bundle bundle = new Bundle();
        bundle.putInt("acid",club.getActivity_id());
        bundle.putString("address",club.getActivity_place());
        bundle.putString("name",club.getActivity_name());
        bundle.putString("phone",club.getActivity_telephone());
        bundle.putString("endtime",club.getActivity_releasetime());
        bundle.putString("intro",club.getActivity_intro());
        bundle.putString("number",club.getActivity_peoplenum()+"");
        bundle.putString("pic", IMG_URL+club.getActivity_picture());
        bundle.putString("price", club.getActivity_free()+"");
        intent.putExtras(bundle);
        mContext.startActivity(intent);
        }
        });
        }

@Override
public int getItemCount() {
        return mList.size();
        }


public class ViewHolder extends RecyclerView.ViewHolder {
    TextView name;
    ImageView pic;

    public ViewHolder(View itemView) {
        super(itemView);
        name = (TextView) itemView.findViewById(R.id.name);
        pic = (ImageView) itemView.findViewById(R.id.pic);

    }
}
}
